/*
 * $Id: ObjectNavigationMenu.java 105 2009-06-30 05:33:29Z donbeave $
 */

package labour.manager.client.widget.menu;

import labour.concept.client.data.ObjectText;

import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;

public class ObjectNavigationMenu extends Menu {

  private MenuItem viewItem;
  private MenuItem refreshItem;
  private CreateDocumentMenuItem createItem;
  private CreateDocumentMenu createMenu;
  private MenuItem publishItem;
  private MenuItem deleteItem;
  private MenuItem propertiesItem;

  private ObjectText model;

  public ObjectNavigationMenu() {
    viewItem = new MenuItem("View");
    refreshItem = new MenuItem("Refresh");
    createItem = new CreateDocumentMenuItem("Create");
    publishItem = new MenuItem("<b>Publish</b>");
    deleteItem = new MenuItem("Delete");
    propertiesItem = new MenuItem("Properties");

    createMenu = new CreateDocumentMenu();
    createItem.setSubMenu(createMenu);

    add(viewItem);
    add(new SeparatorMenuItem());
    add(refreshItem);
    add(new SeparatorMenuItem());
    add(createItem);
    add(new SeparatorMenuItem());
    add(publishItem);
    add(deleteItem);
    add(new SeparatorMenuItem());
    add(propertiesItem);
  }

  public ObjectText getItem() {
    return model;
  }

  public void setItem(ObjectText model) {
    this.model = model;

    if (model.getObject().hasChildren()) {
      getRefreshItem().enable();
    } else {
      getRefreshItem().disable();
    }

    if (model.getModel().isPublished()) {
      getPublishItem().setText("Unpublish");
    } else {
      getPublishItem().setText("<b>Publish</b>");
    }
  }

  public MenuItem getViewItem() {
    return viewItem;
  }

  public MenuItem getRefreshItem() {
    return refreshItem;
  }

  public CreateDocumentMenuItem getCreateItem() {
    return createItem;
  }

  public MenuItem getPublishItem() {
    return publishItem;
  }

  public MenuItem getDeleteItem() {
    return deleteItem;
  }

  public MenuItem getPropertiesItem() {
    return propertiesItem;
  }

}
